/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonysite.sessionbean;

import com.matrimonysite.entity.UserPersonal;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author khanhnguyen
 */
@Stateless
public class UserPersonalFacade extends AbstractFacade<UserPersonal> {

    @PersistenceContext(unitName = "MatrimonySite-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UserPersonalFacade() {
        super(UserPersonal.class);
    }

    @Override
    public void create(UserPersonal userpersonal) {
        em.persist(userpersonal);
    }

    @Override
    public void edit(UserPersonal userpersonal) {
        em.merge(userpersonal);
    }

    @Override
    public void remove(UserPersonal userpersonal) {
        em.remove(em.merge(userpersonal));
    }

    public UserPersonal getPersonalID(String personalID) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByProfileID");
            q.setParameter("personalID", personalID);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getSelfFeatures(String selfFeatures) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findBySelfFeatures");
            q.setParameter("selfFeatures", selfFeatures);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getFamilyDetails(String familyDetails) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByFamilyDetails");
            q.setParameter("familyDetails", familyDetails);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getWorkAt(String workAt) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByWorkAt");
            q.setParameter("workAt", workAt);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getQualificationStatus(String qualificationStatus) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByQualificationStatus");
            q.setParameter("qualificationStatus", qualificationStatus);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getDesignation(String designnation) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByDesignation");
            q.setParameter("designnation", designnation);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getFavoriteHobbies(String favoriteHobbies) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByFavoriteHobbies");
            q.setParameter("favoriteHobbies", favoriteHobbies);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getFavoriteMusics(String favoriteMusics) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByFavoriteMusics");
            q.setParameter("favoriteMusics", favoriteMusics);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getFavoriteMovies(String favoriteMovies) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByFavoriteMovies");
            q.setParameter("favoriteMovies", favoriteMovies);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getFavoriteBooks(String favoriteBooks) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByFavoriteBooks");
            q.setParameter("favoriteBooks", favoriteBooks);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getFavoriteCuisines(String favoriteCuisines) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByFavoriteCuisines");
            q.setParameter("favoriteCuisines", favoriteCuisines);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }

    public UserPersonal getFavoritePlace(String favoritePlace) {
        UserPersonal personal = null;
        try {
            Query q = em.createNamedQuery("UserPersonal.findByFavoritePlace");
            q.setParameter("favoritePlace", favoritePlace);
            personal = (UserPersonal) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return personal;
    }
    
    public List<UserPersonal> getAllUserPersonal(){
        Query query= em.createNamedQuery("UserPersonal.findAll");
        return query.getResultList();
    }
}
